package com.ruoyi.hatha.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.hatha.domain.PYkecheng;
import com.ruoyi.hatha.service.IPYkechengService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.hatha.domain.PKcb;
import com.ruoyi.hatha.service.IPKcbService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 课程表Controller
 * 
 * @author ruoyi
 * @date 2024-04-15
 */
@RestController
@RequestMapping("/hatha/kcb")
public class PKcbController extends BaseController
{
    @Autowired
    private IPKcbService pKcbService;
    @Autowired
    private IPYkechengService ykechengService;

    /**
     * 查询课程表列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:kcb:list')")
    @GetMapping("/list")
    public TableDataInfo list(PKcb pKcb)
    {
        startPage();
        List<PKcb> list = pKcbService.selectPKcbList(pKcb);
        return getDataTable(list);
    }


    @GetMapping("/getlist")
    public AjaxResult getlist(PKcb pKcb)
    {
        List<PKcb> list = pKcbService.selectPKcbList(pKcb);
//        for(int i=0;i<list.size();i++){
//            Long id = list.get(i).getId();
//            PYkecheng pYkecheng = new PYkecheng();
//            pYkecheng.setBid(id);
//            pYkecheng.setUid(SecurityUtils.getUserId());
//            List<PYkecheng> lpys = ykechengService.getList(pYkecheng);
//            list.get(i).setYkecheng(lpys);
//        }

        return AjaxResult.success(list);
    }

    /**
     * 导出课程表列表
     */
    @PreAuthorize("@ss.hasPermi('hatha:kcb:export')")
    @Log(title = "课程表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PKcb pKcb)
    {
        List<PKcb> list = pKcbService.selectPKcbList(pKcb);
        ExcelUtil<PKcb> util = new ExcelUtil<PKcb>(PKcb.class);
        util.exportExcel(response, list, "课程表数据");
    }

    /**
     * 获取课程表详细信息
     */
    @PreAuthorize("@ss.hasPermi('hatha:kcb:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pKcbService.selectPKcbById(id));
    }

    /**
     * 新增课程表
     */
    @PreAuthorize("@ss.hasPermi('hatha:kcb:add')")
    @Log(title = "课程表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PKcb pKcb)
    {
        return toAjax(pKcbService.insertPKcb(pKcb));
    }

    /**
     * 修改课程表
     */
    @PreAuthorize("@ss.hasPermi('hatha:kcb:edit')")
    @Log(title = "课程表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PKcb pKcb)
    {
        return toAjax(pKcbService.updatePKcb(pKcb));
    }

    /**
     * 删除课程表
     */
    @PreAuthorize("@ss.hasPermi('hatha:kcb:remove')")
    @Log(title = "课程表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pKcbService.deletePKcbByIds(ids));
    }
}
